package config

import (
	"os"
	"strings"
)

var Conf Config

type Config struct {
	BindPort      string
	DockerHost    string
	WorkSpacePath string
}

func (c *Config) InitialConfig() error {

	//service binding port
	bindport := os.Getenv("ETL_BIND_PORT")
	if strings.EqualFold(bindport, "") {
		c.BindPort = ":30000"
	} else {
		c.BindPort = ":" + bindport
	}

	//service working path
	workspacepath := os.Getenv("ETL_SERVICE_WORKSPACE_PATH")
	if strings.EqualFold(workspacepath, "") {
		c.WorkSpacePath = "./jobstore"
	} else {
		c.WorkSpacePath = workspacepath
	}

	//mkdir workspace
	os.MkdirAll(c.WorkSpacePath, os.ModePerm)

	dockerhost := os.Getenv("ETL_SERVICE_DOCKERHOST")
	if strings.EqualFold(dockerhost, "") {
		c.DockerHost = "localhost:4243"
	} else {
		c.DockerHost = dockerhost
	}

	return nil
}
